package atag.runtime.ln.nodeAttributes;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * Defines a static boolean attribute.
 * 
 */
public class BooleanAttribute extends NodeAttribute {

	/**
	 * Creates a new instance of this attribute.
	 */
	public BooleanAttribute() {
	}

	/**
	 * Creates a new instance of this attribute.
	 * 
	 * @param key the name of the attribute.
	 * @param value the value associated.
	 */
	public BooleanAttribute(String key, boolean value) {

		this.key = key;
		this.value = new Boolean(value);
	}

	public String toString() {

		return "BooleanAttribute key = " + key + ", value = " + value;
	}

    public DataOutput serialize(DataOutput dg) throws IOException {

        dg.writeByte(BOOL_ATTR_TYPE);
        super.serialize(dg);
        dg.writeUTF(key);
        dg.writeUTF(this.value.toString());
        return dg;
    }

     public static NodeAttribute deserialize(DataInput dg) throws IOException
     {
         String key = dg.readUTF();
         Boolean value = Boolean.valueOf(dg.readUTF());
         BooleanAttribute ba = new BooleanAttribute(key,value.booleanValue());
         return ba;
     }

}
